package main

import (
	"log"
	"net"
	"net/rpc"
)

type HelloService struct {
}

func (p *HelloService) Hello(request string, reply *string) error {
	log.Println("call method: HelloService.Hello")
	*reply = "hello:" + request
	return nil
}

func main() {
	rpc.RegisterName("HelloService", new(HelloService))
	listener, err := net.Listen("tcp", ":1234")
	if err != nil {
		log.Fatal("ListenTCP error: ", err)
	} else {
		log.Printf("ListenTCP: %s", ":1234")
		log.Println("waiting client")
	}

	for {
		conn, err := listener.Accept()
		log.Println(conn.RemoteAddr().String(), conn.RemoteAddr().Network())
		if err != nil {
			log.Fatal("Accept error: ", err)
		}
		go rpc.ServeConn(conn)
	}
}
